package com.syh.transactionservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.syh.bscommon.pojo.Transactions;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author syh
 * @since 2024-07-02
 */
@Mapper
public interface TransactionsMapper extends BaseMapper<Transactions> {
    @Select("SELECT * FROM transactions WHERE seller_id != #{sellerId} order by id desc")
    List<Transactions> getTransactions(Integer sellerId);
    @Select("SELECT final_avg FROM transactions WHERE id = #{id}")
    BigDecimal getById_transactions(Integer id);
    @Select("SELECT * FROM transactions WHERE buyer_id = #{buyerId} AND type = '定价出售' AND status = '卖家已确认' ")
    List<Transactions> getTransactionsByBuyerId(Integer buyerId);
    @Select("SELECT * FROM transactions WHERE seller_id = #{sellerId} AND type = '定价出售' AND status = '已提交' ")
    List<Transactions> getTransactionsBySellerId(Integer sellerId);
    @Select("SELECT * FROM transactions WHERE seller_id = #{sellerId} AND type = '竞拍出售' AND status = '竞拍中' ")
    List<Transactions> getTransactionsBySellerId_a(Integer sellerId);
    @Select("SELECT * FROM transactions WHERE buyer_id = #{buyerId} AND type = '竞拍出售' AND status = '卖家结束竞拍' ")
    List<Transactions> getTransactionsByBuyerId_a(Integer buyerId);
    @Select("SELECT * FROM transactions WHERE status = '已发布' ")
    List<Transactions> getList();
    @Select("SELECT * FROM transactions WHERE status = '买家已确认' ")
    List<Transactions> getLists();
    @Select("SELECT credit_amount FROM transactions WHERE status = '审核通过' AND buyer_id = #{buyerId} " +
            "ORDER BY transactions.transaction_date desc LIMIT 0,2")
    List<BigDecimal> getTMR(Integer buyerId);
    @Select("SELECT final_sum FROM transactions WHERE (status = '审核通过' OR status = '买家已确认') " +
            " AND buyer_id = #{buyerId} " +
            "ORDER BY transactions.transaction_date desc LIMIT 0,2")
    List<BigDecimal> getTMRvalue(Integer buyerId);
    @Select("SELECT final_sum FROM transactions WHERE (status = '审核通过' OR status = '买家已确认') " +
            " AND seller_id = #{sellerId} " +
            "ORDER BY transactions.transaction_date desc LIMIT 0,2")
    List<BigDecimal> getTMCvalue(Integer sellerId);
    @Select("SELECT * FROM transactions WHERE seller_id = #{sellerId}")
    List<Transactions> getTransactionSell(Integer sellerId);
    @Select("SELECT * FROM transactions WHERE buyer_id = #{buyerId}")
    List<Transactions> getTransactionBuy(Integer buyerId);
}
